Skip to content

fix: keep a call body that moved to the next line after multi-line arrow parameters there when formatting again - #897

Merged
dsherret merged 2 commits into
dprint:mainfrom
todor-a:fix-unstable-arrow-call-body
Nov 5, 2026
Merged

dsherret merged 2 commits into
dprint:mainfrom
todor-a:fix-unstable-arrow-call-body

Conversation

@todor-a

@todor-a todor-a commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Transparency note: This PR was prepared with AI assistance.


Fixes #896.

Makes an arrow function format the same way on every pass when its parameters span several lines and its body is a call whose last argument spans several lines.

Problem

With indentWidth: 4 and the default lineWidth, 0.97.0 never settles on this input, and the CLI bails with Formatting not stable:

values.forEach((
    value,
) => it("formats the value when this line is longer than the default line width of one hundred and twenty characters", () => {
    test(value);
}));

The first pass moves the call to the line after ) =>. The second pass puts it back on the arrow's line, and so on. #896 has the output of each pass. 0.96.1 leaves the input unchanged. With indentWidth: 2, 0.97.0 moves the call to the next line and keeps it there.

Cause

#861 added is_hugging_call_body in gen_arrow_func_expr. When the call starts on the arrow's line and its last argument starts on that line and spans more lines, the separator after => is Signal::SpaceOrNewLine. Here the text before the last argument doesn't fit, so the call moves to the next line.

On the next pass the call is no longer on the arrow's line, so the body takes the older path: if_above_width_or(indent_width, ..., " "). ) => ends at column 4, which is not past the indent width of 4, so that path prints a space and the call goes back on the arrow's line. With indentWidth: 2 the column is past the indent width, the body spans several lines, and the older path keeps the newline. That is why only indentWidth: 4 alternates.

Change

In the older path, when the column is not past the indent width and the body is a call that hugs its last argument, the separator is now Signal::SpaceOrNewLine instead of a space. That is the separator #861's branch uses, so the result no longer depends on whether the input had the call on the arrow's line:

  • A call that doesn't fit after ) => moves to the next line and stays there.
  • A call that fits after ) => is put on the arrow's line, as 0.97.0 does today.

The call-shape check moves out of is_hugging_call_body into is_call_hugging_last_arg, so both paths use it. Bodies that aren't such a call still get a space, and headers past the indent width are unchanged.

Tests

Real code

I built the Wasm plugin and ran it with CLI 0.64.3 and a config with lineWidth: 180 and indentWidth: 4:

  • The 5,619-line test file where we first saw this formats with exit 0. With 0.97.0 it fails with Formatting not stable. The build changes one it(...) body in it: it moves to the line after ) =>.
  • On two TypeScript services (about 210 files changed by 0.97.0 itself), the build changes no file beyond what 0.97.0 changes. A second dprint fmt changes nothing, and dprint check passes.

@dsherret dsherret left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry about that.

@dsherret
dsherret merged commit dca0e47 into dprint:main Nov 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatting not stable for a test call body after multi-line arrow parameters (regression in 0.97.0, #861)

2 participants